import axios from "axios";
const https = axios.create({
  baseURL: "http://127.0.0.1:7002"
  // baseURL: "http://127.0.0.1:7001"
  // baseURL: "http://47.98.109.207:7001"
  // baseURL: "http://eren200.yicp.io"
});

// 添加请求拦截器
https.interceptors.request.use(
  config => {
    let token = window.localStorage.getItem("token");
    if (token) {
      config.headers["authorization"] = token;
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

https.interceptors.response.use(
  response => {
    return response.data;
  },
  error => {
    if (error.response.status === 401) {
      window.vm.$message("令牌错误-无权限");
      window.vm.$router.push("/login");
    }
    return Promise.reject(error);
  }
);

export default https;
